package com.ycsj.goldmedalnewconcept.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.readystatesoftware.systembartint.SystemBarTintManager;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.constant.ConfigConstant;
import com.ycsj.goldmedalnewconcept.constant.NetConstant;
import com.ycsj.goldmedalnewconcept.utils.SPUtils;

import java.io.IOException;

public class ageSelectActivity extends BaseJpStarActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ageselect);
		
		SystemBarTintManager tintManager = new SystemBarTintManager(this);
		tintManager.setStatusBarTintEnabled(true);
		tintManager.setStatusBarTintResource(R.color.base_color);
		
		
		ListView lv_age = (ListView) findViewById(R.id.lv_age);
		lv_age.setAdapter(new Myadapter());
		lv_age.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				SPUtils.put(ageSelectActivity.this, "selectAge", ages[position]);
				
				String pathAge=NetConstant.ACCOUNTINFO+ "/UpdateStudentInfo.aspx?account="+ SPUtils.getString(ageSelectActivity.this,
						ConfigConstant.USERNAME)+ "&u_c=2&usertoken="+ SPUtils.getString(ageSelectActivity.this,
						ConfigConstant.USERTOKEN)+"&type=3&value="+ages[position];
				OkHttpClient mOkHttpClient = new OkHttpClient();
				// 创建一个Request
				final Request request = new Request.Builder().url(pathAge).build();
				Call call = mOkHttpClient.newCall(request);
			
				// 请求加入调度
				call.enqueue(new Callback() {
					
					@Override
					public void onResponse(Response arg0) throws IOException {
						// TODO Auto-generated method stub
						
					}
					
					@Override
					public void onFailure(Request arg0, IOException arg1) {
						// TODO Auto-generated method stub
						
					}
				});
				finish();
			}
			
		});
	}
		
	String ages[]= {"4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"
			,"20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39"
			,"40","41","42","43","44","45"}; 

	class Myadapter extends BaseAdapter{

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return ages.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}
		ViewHolder vh=null;
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				vh = new ViewHolder();
				convertView = View.inflate(parent.getContext(),
						R.layout.item_age, null);
				vh.tv_age=(TextView) convertView.findViewById(R.id.tv_age);
				convertView.setTag(vh);
			}else{
				vh = (ViewHolder) convertView.getTag();
			}
			
			vh.tv_age.setText(ages[position]);
			
			return convertView;
		}
		
		class ViewHolder {
			private TextView tv_age;
			
		}
		
	}
}
